package com.yellowpage.wf.service;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;
import com.yellowpage.wf.dao.NodeAttachmentInstanceDao;
import com.yellowpage.wf.data.NodeAttachmentInstance;

public class NodeAttachmentInstanceServiceImpl extends BaseServiceImpl implements NodeAttachmentInstanceService {
	  private NodeAttachmentInstanceDao nodeAttachmentInstanceDao;
	  public void setNodeAttachmentInstanceDao(
			NodeAttachmentInstanceDao nodeAttachmentInstanceDao) {
		this.nodeAttachmentInstanceDao = nodeAttachmentInstanceDao;
	}
	/* White generate Method */ 
	  public void saveNodeAttachmentInstance(NodeAttachmentInstance nodeAttachmentInstance)
	  {
		  nodeAttachmentInstanceDao.save(nodeAttachmentInstance);
	  }
	  public void delete(List deleteList){
		  nodeAttachmentInstanceDao.remove(deleteList);
	  }
	  public List<Map> getNodeAttachmentInstanceVersion(Long nodeInstanceId,Long nodeAttachmentId){
			String sql = "select max(wnai.version) as version from wf_node_attachment_instance wnai where " +
					" wnai.workflow_node_instance_id = "+nodeInstanceId.toString()+
					" and wnai.node_attachment_id = "+nodeAttachmentId.toString();

			QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(sql);
			List<Map> resultList = this.baseDao.query(sqlAssistant, new HashMap());
			return resultList;
		}
	  
	  public List<Map> getNodeAttachmentInstanceHis(Long nodeAttachmentId){
		  String sql = "select t.version,t.resource_id,wr.name as fname,wr.type,wr.dir " +
		  		" from wf_node_attachment_instance t,wf_resource wr " +
		  		" where t.resource_id = wr.resource_id " +
		  		" and t.node_attachment_id = "+nodeAttachmentId.toString();

		  QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(sql);
		  List<Map> resultList = this.baseDao.query(sqlAssistant, new HashMap());
		  return resultList;
	  }
}	